<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>你好</title>
</head>

<body>
    <button>按钮1</button>
    <button>按钮2</button>
    <button>按钮3</button>
    <button>按钮4</button>
    <button>按钮5</button>
</body>
<script>
    var els = document.getElementsByTagName("button")

    for (var i = 0; i < els.length; i++) {
        els[i].onclick = changeColor
    }
    function changeColor() {

        for (var i = 0; i < els.length; i++) {
            els[i].style.backgroundColor = ""
        }
        this.style.backgroundColor = "red"
    }
</script>

</html>